﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QuanLyKhachSan
{
    public partial class UC_Group_Edit : System.Web.UI.UserControl
    {
        private int GroupID = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.Request.QueryString["GroupID"] != null)
                {
                    GroupID = int.Parse(this.Request.QueryString["GroupID"].ToString());
                }
                if (!Page.IsPostBack)
                {
                    if (GroupID != -1)
                    {
                        Group_Load();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Group_Load
        /// </summary>
        protected void Group_Load()
        {
            try
            {
                GroupInfo item = GroupBLL.Group_GetItem(GroupID);
                txtGroupName.Text = item.GroupName;
                txtDescriptions.Text = item.Descriptions;
                if (item.IsActived == 1)
                    chkIsActived.Checked = true;
                else
                    chkIsActived.Checked = false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {
                int IsActived = 0;
                if (chkIsActived.Checked)
                    IsActived = 1;

                if (GroupID == -1)
                {
                    GroupBLL.Group_Add(txtGroupName.Text, txtDescriptions.Text, IsActived, 0, DateTime.Now.ToString("MM/dd/yyyy"));   
                }
                else
                {
                    GroupBLL.Group_Edit(GroupID, txtGroupName.Text, txtDescriptions.Text, IsActived, 0, DateTime.Now.ToString("MM/dd/yyyy"));   
                }
                hfStatus.Value = "1";
            }
            catch (Exception)
            {
                
                throw;
            }
        }
}
}
